package typejump.commands;

import typejump.Settings;
import typejump.Swagger;
import typejump.TypeJump;
import typejump.engine.GameEngine;
import typejump.objects.Actor;
import typejump.sound.SoundManager;

public class Jump implements TextCommand {
	
	private double costPerJump = Settings.getDouble("jump.cost");
	
	@Override
	public boolean matches(String command) {
		return command.toLowerCase().matches("jump");
	}

	
	private static String[] MODS = {"", "SINGLE", "DOUBLE", "TRIPLE", "QUADRUPLE", "PENTUPLE", "HEXTUPLE", "SEPTUPLE", "OCTUPLE", "NONUPLE", "DECUPLE"};
	private String getJumpText(int times) {
		if (times <= 0) return "";
		if (times == 1) return "JUMP";
		if (times >= 2 && times < MODS.length)
			return MODS[times] + " JUMP";
		return times + "x SUPER JUMP";
	}
	
	@Override
	public void act(String command) {
		Actor player = TypeJump.getInst().getPlayer();

		if (player.isOnGround()) {
			player.vars().set("jumps", -1);
		}
		
		int min = player.vars().get("jumps")+1;
		if (min <= 0 || Swagger.getInst().tryExpendSwag(costPerJump * min)) {
			player.vars().mod("jumps", 1);
			jump(player);
			
			GameEngine.addTextEffect(getJumpText(min+1), "jump");
			SoundManager.PLAYER.play("jump.wav");
		}

	}
	
	private void jump(Actor player) {
		player.vy(player.getJumpVelocity());
	}
}
